﻿Public Class calc
    Private Sub oneBtn_Click(sender As Object, e As EventArgs) Handles oneBtn.Click
        valText.Text += "1"
    End Sub

    Private Sub twoBtn_Click(sender As Object, e As EventArgs) Handles twoBtn.Click
        valText.Text += "2"
    End Sub

    Private Sub threeBtn_Click(sender As Object, e As EventArgs) Handles threeBtn.Click
        valText.Text += "3"
    End Sub

    Private Sub fourBtn_Click(sender As Object, e As EventArgs) Handles fourBtn.Click
        valText.Text += "4"
    End Sub

    Private Sub fiveBtn_Click(sender As Object, e As EventArgs) Handles fiveBtn.Click
        valText.Text += "5"
    End Sub

    Private Sub sixBtn_Click(sender As Object, e As EventArgs) Handles sixBtn.Click
        valText.Text += "6"
    End Sub

    Private Sub sevenBtn_Click(sender As Object, e As EventArgs) Handles sevenBtn.Click
        valText.Text += "7"
    End Sub

    Private Sub eightBtn_Click(sender As Object, e As EventArgs) Handles eightBtn.Click
        valText.Text += "8"
    End Sub

    Private Sub nineBtn_Click(sender As Object, e As EventArgs) Handles nineBtn.Click
        valText.Text += "9"
    End Sub

    Private Sub zeroBtn_Click(sender As Object, e As EventArgs) Handles zeroBtn.Click
        valText.Text += "0"
    End Sub

    Private Sub pointBtn_Click(sender As Object, e As EventArgs) Handles pointBtn.Click
        valText.Text += "."
    End Sub

    Private Sub equalBtn_Click(sender As Object, e As EventArgs) Handles equalBtn.Click
        Try
            Dim ret = New DataTable().Compute(valText.Text, Nothing)
            valText.Text = ret
        Catch ex As Exception
            Console.WriteLine("发生错误" & ex.Message)
            MessageBox.Show("输入的表达式有误"， "出错了")
        End Try
    End Sub

    Private Sub addBtn_Click(sender As Object, e As EventArgs) Handles addBtn.Click
        valText.Text += "+"
    End Sub

    Private Sub reductionBtn_Click(sender As Object, e As EventArgs) Handles reductionBtn.Click
        valText.Text += "-"
    End Sub

    Private Sub timesBtn_Click(sender As Object, e As EventArgs) Handles timesBtn.Click
        valText.Text += "*"
    End Sub

    Private Sub divideBtn_Click(sender As Object, e As EventArgs) Handles divideBtn.Click
        valText.Text += "/"
    End Sub

    Private Sub clearBtn_Click(sender As Object, e As EventArgs) Handles clearBtn.Click
        valText.Text = ""
    End Sub

    Private Sub LPBtn_Click(sender As Object, e As EventArgs) Handles LPBtn.Click
        valText.Text += "("
    End Sub

    Private Sub RPBtn_Click(sender As Object, e As EventArgs) Handles RPBtn.Click
        valText.Text += ")"
    End Sub

    Private Sub backBtn_Click(sender As Object, e As EventArgs) Handles backBtn.Click
        Try
            valText.Text = valText.Text.Substring(0, valText.Text.Length - 1)
        Catch ex As Exception
            Console.WriteLine("发生错误" & ex.Message)
            valText.Text = ""
        End Try
    End Sub
End Class
